let fetch = require("../../utils/fetch");
let app = getApp();
Page({
    data: {
        count: 10,
        imageUrl: app.globalData.imageUrl,
        pageNum: 1,
        balanceList: [],
        isLast: false,
        isLoading: false

    },
    onLoad: function (options) {
        // 生命周期函数--监听页面加载
        this.loadDetail(1)
    },
    onReady: function () {
        // 生命周期函数--监听页面初次渲染完成

    },

    loadDetail: function (pageNum) {
        this.setData({isLoading: true})
        fetch
            .balanceDetail(pageNum)
            .then((response) => {
                const res = response.data;
                this.setData({isLoading: false})
                if (res.code == 200) {
                    this.setData({
                        balanceList:this.data.balanceList.concat(res.obj.result) ,
                        pageNum: this.data.pageNum + 1
                    })
                    if (res.obj.currentPage >= res.obj.totalPage) {
                        this.setData({isLast: true})
                    }
                }
            })
            .catch((error) => {
                this.setData({isLoading: false})
                fetch.showMyToast(this, error.data.des)
            })
    },
    onPullDownRefresh: function () {
        // 页面相关事件处理函数--监听用户下拉动作
        return
    },
    onReachBottom: function () {
        // 页面上拉触底事件的处理函数
        if(this.data.isLast || this.data.isLoading){
            return
        }else{
           this.loadDetail(this.data.pageNum) 
        }
       
    },
    onShareAppMessage: function () {
        return {title: '欢迎来到小麦铺智能便利店', path: "pages/loading/loading"}
    }

})